package com.innerchic.weqiuqiu.adapter;

import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.os.Parcelable;

import androidx.recyclerview.widget.RecyclerView;

import com.innerchic.annotations.base.BindViewLayoutHolder;
import com.innerchic.mapper.app.SuperAdapter;
import com.innerchic.weqiuqiu.R;
import com.innerchic.weqiuqiu.bean.old.MessageMade;

/**
 * ================================================
 * 作    者：贾恒飞 >>> 17515250730@163.com
 * 项    目：wedudu
 * 日    期：2022/1/11 16:46
 * 包    名：com.innerchic.wedudu.adapter
 * 描    述：消息适配器
 * Create by zFox from AndroidStudio4.2
 * ================================================
 */
@BindViewLayoutHolder("adapter_message")
public class MessageAdapter extends SuperAdapter<MessageMade> {

    @Override
    protected void adapterBindViewHolder(RecyclerView.ViewHolder holder, MessageMade data, int position) {
        MessageAdapterHolder format = MessageAdapterHolder.format(holder);
        Parcelable heardBitmap = data.getHeardBitmap();
        try {
            Bitmap bitmap = (Bitmap) heardBitmap;
            format.heardImage.setImageBitmap(bitmap);
        } catch (Exception e) {
            Icon icon = (Icon) heardBitmap;
            format.heardImage.setImageIcon(icon);
        }
        format.nameText.setText(data.getTitle());
        format.contentText.setText(data.getContent());

        format.heardImage.setOnClickListener(v -> {
            getMonitor().onMonitor(v, data, position, 1);
        });

        format.contentText.setOnClickListener(v -> {
            getMonitor().onMonitor(v, data, position, 2);
        });
    }

    @Override
    protected int getLayoutRes(int viewType) {
        return R.layout.adapter_message;
    }

}
